/*
 * COPYRIGHT. ShenZhen iByte Technology Co., Ltd. 2018.
 * ALL RIGHTS RESERVED.
 *
 * No part of this publication may be reproduced, stored in a retrieval system, or transmitted,
 * on any form or by any means, electronic, mechanical, photocopying, recording, 
 * or otherwise, without the prior written permission of ShenZhen iByte Network Technology Co., Ltd.
 *
 * Amendment History:
 * 
 * Date                   By              Description
 * -------------------    -----------     -------------------------------------------
 * Nov 30, 2018    Li.shangzhi         Create the class
*/
package com.github.icloud.elasticsearch.api.docment;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.get.MultiGetItemResponse;
import org.elasticsearch.action.get.MultiGetResponse;
import org.junit.Test;
import com.github.icloud.elasticsearch.ElasticsearchClientBase;
/**
 * @FileName MultiGetAPI.java
 * @Description: 一次获取多个文档
 *
 * @Date Nov 30, 2018 6:45:17 PM
 * @author Li.shangzhi
 * @version 1.0
 */
public class MultiGetAPI extends ElasticsearchClientBase {

	@Test
	public void iEsMultiGetAPI() throws Exception{
		MultiGetResponse multiGetResponse = client.prepareMultiGet()
				.add("icloud-alarm", "icloud-monitor-alarm", "4f0b2a9cc4584b92a1f335ed071afe42")
				.add("icloud-iot-log", "icloud-auth", "0da30882066f4818b89b99317c3b3513")
				.add("icloud-alarm", "icloud-monitor-alarm", "4f0b2a9cc4584b92a1f335ed071afe42")
				.get();
		for (MultiGetItemResponse itemResponse : multiGetResponse) {
			GetResponse response = itemResponse.getResponse();
			if (response!=null && response.isExists()) {
				String json = response.getSourceAsString(); //_source 字段
				System.out.println("_soure:"+json);
			}
		}
			
	}
}
